package com.tl.sun.ui.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tl.sun.R;
import com.tl.sun.model.PackageEntity;

import java.util.List;

/**
 * 作者：HQY on 17/10/17 13:11
 * 邮箱：hqy_xz@126.com
 */

public class PackageAdapter extends BaseQuickAdapter<PackageEntity, BaseViewHolder> {


    public PackageAdapter(List<PackageEntity> data) {
        super(R.layout.item_package, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PackageEntity item) {

        ImageView mIvbg = helper.getView(R.id.iv_package_bg);
        ImageView mIvOne = helper.getView(R.id.iv_left_one);
        ImageView mIvThree = helper.getView(R.id.iv_left_three);
        TextView mTvSubmit = helper.getView(R.id.tv_package_submit);

        helper.setText(R.id.tv_package_name, item.getName())
                .setText(R.id.tv_package_money, "￥" + item.getShowPrice())
                .addOnClickListener(R.id.tv_package_submit);

        int redbg = 0;
        if (helper.getAdapterPosition() == 0) {
            mIvOne.setVisibility(View.VISIBLE);
            mIvThree.setVisibility(View.GONE);
            redbg = R.drawable.package_top_one;

            mTvSubmit.setBackground(mContext.getResources().getDrawable(R.drawable.package_btn_one));
        } else if (helper.getAdapterPosition() == 1) {
            mIvOne.setVisibility(View.GONE);
            mIvThree.setVisibility(View.GONE);
            redbg = R.drawable.package_top_two;
            mTvSubmit.setBackground(mContext.getResources().getDrawable(R.drawable.package_btn_two));
        } else if (helper.getAdapterPosition() == 2) {
            mIvOne.setVisibility(View.GONE);
            mIvThree.setVisibility(View.VISIBLE);
            redbg = R.drawable.package_top_three;
            mTvSubmit.setBackground(mContext.getResources().getDrawable(R.drawable.package_btn_three));
        }
        Glide.with(mContext)
                .load(redbg)
                .placeholder(R.drawable.package_top_one)
                .error(R.drawable.package_top_one)
                .into(mIvbg);
    }
}
